package com.atguigu.gmall.util;

/**
 * MySql工具类
 *
 * @author : ranzlupup
 * @since : 2023/6/3 11:47
 */
public class MysqlUtils {

    /**
     * 读取mysql base_dic 创建 base_dic LookUp表
     * ! 需要加上主键 primary key(`dic_code`) not enforced
     */
    public static String getBaseDicLookUpDDL() {
        return "create table `base_dic`( " +
                "`dic_code` string, " +
                "`dic_name` string, " +
                "`parent_code` string, " +
                "`create_time` timestamp, " +
                "`operate_time` timestamp, " +
                "primary key(`dic_code`) not enforced " +
                ")" + MysqlUtils.mysqlLookUpTableDDL("base_dic");
    }

    /**
     * 使用Flink-mysql-connector读取MySQL的表 创建 LookUp表（维表）
     *
     * @param tableName MySQL对应的表名
     */
    public static String mysqlLookUpTableDDL(String tableName) {

        return " WITH ( " +
                "'connector' = 'jdbc', " +
                "'url' = 'jdbc:mysql://hadoop102:3306/gmall-flink', " +
                "'table-name' = '" + tableName + "', " +
                "'lookup.cache.max-rows' = '10', " +
                "'lookup.cache.ttl' = '1 hour', " +
                "'username' = 'root', " +
                "'password' = '123456', " +
                "'driver' = 'com.mysql.cj.jdbc.Driver' " +
                ")";
    }
}
